import { each, isArray } from 'lodash'
import { nFormatter } from '@/utils/nFormatter'

const candlestickStart = 30

export default {
  legend: {
    show: true,
    left: 'center',
    icon: 'rect',
    data: ['每日用气量', '指数平滑', '小波神经网络预测'],
    itemHeight: 12,
    itemWidth: 20,
    padding: [10, 10, 10, 10]
  },
  tooltip: {
    appendToBody: true,
    formatter: function(val = []) {
      let showStr = ''
      each(val, item => {
        const { seriesType } = item
        const { marker, data = {}, seriesName } = item
        const { name, value } = data
        if (seriesType === 'candlestick') {
          const [, open = 0, close = 0, top = 0, bottom = 0] = value
          showStr = `
              ${name}<br/>
              ${marker}00:00:${open}<br/>
              ${marker}23:59:${close}<br/>
              ${marker}最大值:${top}<br/>
              ${marker}最小值:${bottom}<br/>
            `
        } else if (seriesType === 'line') {
          if (isArray(value)) {
            showStr += `${marker}${seriesName}:${value[1]}<br/>`
          } else {
            showStr += `${marker}${seriesName}:${value}<br/>`
          }
        }
      })
      return showStr
    }
  },
  dataZoom: [
    {
      show: false,
      start: candlestickStart,
      end: 100
    },
    {
      show: false,
      start: candlestickStart,
      top: '90%',
      end: 100,
      height: 20
    }
  ],
  xAxis: {
    type: 'category',
    name: '日期',
    nameGap: 25,
    nameLocation: 'center',
    show: true,
    nameTextStyle: {
      color: '#fff'
    },
    scale: true,
    position: 'bottom'
  },
  yAxis: [
    {
      scale: true,
      name: '累计读数',
      position: 'right',
      splitArea: {
        show: false
      },
      splitLine: {
        lineStyle: {
          color: '#31597d',
          type: 'dashed'
        }
      },
      nameTextStyle: {
        color: '#fff'
      },
      axisLine: {
        onZero: false,
        lineStyle: {
          color: '#31597d'
        }
      },
      axisLabel: {
        formatter: function(val) {
          return nFormatter(val)
        }
      }
    },
    {
      scale: true,
      name: '每日用气量',
      position: 'left',
      splitArea: {
        show: false
      },
      splitLine: {
        lineStyle: {
          color: '#31597d',
          type: 'dashed'
        }
      },
      nameTextStyle: {
        color: '#fff'
      },
      axisLine: {
        onZero: false,
        lineStyle: {
          color: '#31597d'
        }
      },
      axisLabel: {
        formatter: function(val) {
          return nFormatter(val)
        }
      }
    }
  ],
  series: [
    {
      markPoint: {
        label: {
          normal: {
            formatter: function(param) {
              return '缺失'
            }
          }
        }
      }
    }
  ],
  grid: {
    left: '7%',
    right: '7%',
    top: 60,
    bottom: 45
  }
}
